<template>
  <basic-container>
    <div class="app-container calendar-list-container">
      <avue-form ref="form"
                 v-model="form"
                 :option="option"
                 @submit="submitJbxx">
      </avue-form>
    </div>
  </basic-container>
</template>
<script>
import { mapGetters } from 'vuex'
import { getStore } from '@/util/store'
import option from '@/const/cust/zyyjk'
import { addObj, updateObj, getObj } from '@/api/cust/health/zyyjk'
export default {
  name: 'table_user',
  data () {
    return {
      option: option,
      jktjid: this.$route.params.id,
      grjbxxid: this.$route.query.grjbxxid,
      jkdn: getStore({ name: 'jkdn' }),
      form: {}
    }
  },
  watch: {
    form: {
      handler: function () {
        this.sum()
        this.$refs.form.clearValidate()
      },
      deep: true
    }
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  created () {
    if (!this.validatenull(this.jktjid) && !this.validatenull(this.grjbxxid)) {
      this.getCust()
    }
  },
  methods: {
    getCust () {
      getObj({ grjbxxid: this.grjbxxid, jktjid: this.jktjid }).then(res => {
        if (!this.validatenull(res.data.data)) {
          this.form = res.data.data[0]
        }
      })
    },
    sum () {
      //2）（3）（4）（14）
      this.form.tzlxqxzdf =
        Number(this.form.tmnrypfm) +
        Number(this.form.tmnryqdjcm) +
        Number(this.form.tmnshsydrwlm) +
        Number(this.form.tmngdstczbqs)
      //11）（12）（13）（29
      this.form.tzlxyxzdf =
        Number(this.form.tmnsjflm) +
        Number(this.form.tmnwwbbbpl) +
        Number(this.form.tmnbybrnhl) +
        Number(this.form.tmnmshmkham)
      //（10）（21）（26）（31）
      this.form.tzlxyinxzdf =
        Number(this.form.tmnyjgsm) +
        Number(this.form.tmnykzkydhm) +
        Number(this.form.tmnpfhkcgm) +
        Number(this.form.tmnrhdbgzm)
      //9）（16）（28）（32）
      this.form.tzlxtszdf =
        Number(this.form.tmngdstczbqs) +
        Number(this.form.tmnykzkydhm) +
        Number(this.form.tmnfbfdm) +
        Number(this.form.tmnsthyhhm)
      //23）（25）（27）（30）
      this.form.tzlxsrzdf =
        Number(this.form.tmnmbhbbyynm) +
        Number(this.form.tmndpfyzjhzh) +
        Number(this.form.tmnyztmm) +
        Number(this.form.tmnypfszzhm)
      //19）（22）（24）（33）
      this.form.tzlxxyzdf =
        Number(this.form.tmndpfrycxqz) +
        Number(this.form.tmnyztmm) +
        Number(this.form.tmndpfrycxqz) +
        Number(this.form.tmnfbfdm)
      //（5）（6）（7）（8）
      this.form.tzlxqyzdf =
        Number(this.form.tmngdmmblm) +
        Number(this.form.tmnryjsjzjlbam) +
        Number(this.form.tmnysshztgb) +
        Number(this.form.tmnrygdhpjx)
      //（15）（17）（18）（20）
      this.form.tzlxtbzdf =
        Number(this.form.tmnmygmyhbslbt) +
        Number(this.form.tmnrygm) +
        Number(this.form.tmndpfryqmzm) +
        Number(this.form.tmndpfyzjhzh)
      //1）（2）（4）（5）（13）其中，（2）（4）（5）（13）反向计分，即1→5，2→4，3→3，4→2，5→1）
      var a = 0,
        b = 0,
        c = 0,
        d = 0
      if (!this.validatenull(this.form.tmnrypfm)) {
        a = 6
      }
      if (!this.validatenull(this.form.tmnshsydrwlm)) {
        b = 6
      }
      if (!this.validatenull(this.form.tmngdmmblm)) {
        c = 6
      }
      if (!this.validatenull(this.form.tmnbybrnhl)) {
        d = 6
      }
      this.form.tzlxphzdf =
        Number(this.form.tmnjlcpm) +
        a +
        b +
        c +
        d -
        Number(this.form.tmnrypfm) -
        Number(this.form.tmnshsydrwlm) -
        Number(this.form.tmngdmmblm) -
        Number(this.form.tmnbybrnhl)
      //控制下拉框
      this.controlBs(this.form.tzlxqxzdf, 'tzlxqxzbs')
      this.controlBs(this.form.tzlxyxzdf, 'tzlxyxzbs')
      this.controlBs(this.form.tzlxyinxzdf, 'tzlxyinxzbs')
      this.controlBs(this.form.tzlxtszdf, 'tzlxtszbs')
      this.controlBs(this.form.tzlxsrzdf, 'tzlxsrzbs')
      this.controlBs(this.form.tzlxxyzdf, 'tzlxxyzbs')
      this.controlBs(this.form.tzlxqyzdf, 'tzlxqyzbs')
      this.controlBs(this.form.tzlxtbzdf, 'tzlxtbzbs')
      //this.controlBs(this.form.tzlxphzdf, 'tzlxphzbs')

      if (
        this.form.tzlxqxzdf <= 8 &&
        this.form.tzlxyxzdf <= 8 &&
        this.form.tzlxyinxzdf <= 8 &&
        this.form.tzlxtszdf <= 8 &&
        this.form.tzlxsrzdf <= 8 &&
        this.form.tzlxxyzdf <= 8 &&
        this.form.tzlxqyzdf <= 8 &&
        this.form.tzlxtbzdf <= 8 &&
        this.form.tzlxphzdf >= 17
      ) {
        this.form.tzlxphzbs = '1'
      } else if (
        this.form.tzlxqxzdf <= 10 &&
        this.form.tzlxyxzdf <= 10 &&
        this.form.tzlxyinxzdf <= 10 &&
        this.form.tzlxtszdf <= 10 &&
        this.form.tzlxsrzdf <= 10 &&
        this.form.tzlxxyzdf <= 10 &&
        this.form.tzlxqyzdf <= 10 &&
        this.form.tzlxtbzdf <= 10 &&
        this.form.tzlxphzdf >= 17
      ) {
        this.form.tzlxphzbs = '2'
      } else {
        this.form.tzlxphzbs = '3'
      }
    },
    controlBs (df, bs) {
      if (!this.validatenull(df)) {
        if (df >= 11) {
          this.form[bs] = '1'
        } else if (df >= 8 && df <= 9) {
          this.form[bs] = '2'
        } else {
          this.form[bs] = '3'
        }
      }
    },
    submitJbxx () {
      if (this.validatenull(this.form.id)) {
        //新增
        this.form.grjbxxid = this.grjbxxid
        this.form.jktjid = this.jktjid
        this.form.name = this.jkdn.name
        this.form.tjbh = this.jkdn.dnbh
        this.form.ysqm = this.jkdn.zeys
        this.form.sfzh = this.jkdn.sfzhm
        this.form.lrr = this.jkdn.lrr
        this.form.lrsj = this.jkdn.lrsj
        addObj(this.form).then(res => {
          this.form = res.data
          this.$message({
            showClose: true,
            message: '提交成功',
            type: 'success'
          })
        })
      } else {
        //更新
        this.form.name = this.jkdn.name
        this.form.tjbh = this.jkdn.dnbh
        this.form.ysqm = this.jkdn.zeys
        updateObj(this.form).then(() => {
          this.$message({
            showClose: true,
            message: '更新成功',
            type: 'success'
          })
        })
      }
    }
  }
}
</script>